package mysql

import "gorm.io/gorm"

type User struct {
	gorm.Model
	Account  string `gorm:"type:varchar(20);not null"`
	Password string `gorm:"type:varchar(32);not null"`
	Username string `gorm:"type:varchar(20);not null"`
	Sex      string `gorm:"type:varchar(20);not null"`
}

func (u *User) FIndUser(db *gorm.DB, account string) error {
	return db.Debug().Where("account=?", account).FirstOrCreate(u).Error
}

func (u *User) DetailsUser(db *gorm.DB, id int64) error {
	return db.Debug().Where("id=?", id).Find(u).Error
}

func (u *User) Update(db *gorm.DB, id int64) error {
	return db.Debug().Where("id=?", id).Updates(u).Error
}
